package com.hmdp.config;

import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author 大忽悠
 * @create 2022/4/29 19:47
 */
@Configuration
public class RedisConfig {
    @Bean
   public RedissonClient redissonClient(@Value("${spring.redis.host}")String redisAddress,
                                        @Value("${spring.redis.port}")String redisPort,
                                        @Value("${spring.redis.password}")String redisPwd){
       //配置类
        Config config=new Config();
        //添加redis地址,这里添加了单点的地址，也可以使用config.useClusterServers()添加集群地址
        config.useSingleServer().setAddress("redis://"+redisAddress+":"+redisPort).setPassword(redisPwd);
        //创建客户端
        return Redisson.create(config);
   }

    @Bean
    public RedissonClient redissonClient1(@Value("${spring.redis1.host}")String redisAddress,
                                         @Value("${spring.redis1.port}")String redisPort,
                                         @Value("${spring.redis1.password}")String redisPwd){
        //配置类
        Config config=new Config();
        //添加redis地址,这里添加了单点的地址，也可以使用config.useClusterServers()添加集群地址
        config.useSingleServer().setAddress("redis://"+redisAddress+":"+redisPort);
        //创建客户端
        return Redisson.create(config);
    }
}
